package com.dk.service.impl;

import com.dk.mapper.PublisherMapper;
import com.dk.pojo.Publisher;
import com.dk.pojo.PublisherExample;
import com.dk.service.PublisherService;
import com.dk.vo.PublisherVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PublisherServiceImpl implements PublisherService {

    @Autowired
    private PublisherMapper publisherMapper;

    @Override
    public PageInfo<PublisherVo> selectUser(Publisher publisher, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<PublisherVo> list = publisherMapper.selectUser(publisher);
        PageInfo<PublisherVo> page = new PageInfo<>(list);
        return page;
    }

    @Override
    public void addUser(Publisher publisher) {
        publisherMapper.insertSelective(publisher);
    }

    @Override
    public Publisher updateInfo(Integer pubId) {
        return publisherMapper.selectByPrimaryKey(pubId);
    }

    @Override
    public void updateAll(Publisher publisher) {
        publisherMapper.updateByPrimaryKeySelective(publisher);
    }

    @Override
    public void deleteInfo(Integer pubId) {
        publisherMapper.deleteByPrimaryKey(pubId);
    }

    @Override
    public List<Publisher> getInfo() {
        PublisherExample example = new PublisherExample();
        List<Publisher> list1 = publisherMapper.selectByExample(example);
        return list1;
    }

    @Override
    public List<Publisher> selectPublishers() {
        PublisherExample example = new PublisherExample();
        List<Publisher> list1 = publisherMapper.selectByExample(example);
        return list1;
    }
}
